package com.zdf.license.web.listener;

import com.zdf.license.core.model.LicenseExtraParam;
import com.zdf.license.verify.listener.ACustomVerifyListener;
import com.zdf.license.verify.listener.ParamType;
import org.springframework.stereotype.Component;

/**
 * 当类注入到springboot中时候，初始化时自动将实例保存在了父类，
 * 每次启动校验父类都会调用 verify(LicenseExtraParam licenseExtra)
 */
@Component
public class UserNumVerifyListener extends ACustomVerifyListener {

    private Integer userNum=0;
    private static final ParamType paramType = new ParamType("userNum", "用户数量", java.lang.Integer.class);

    @Override
    public void install(LicenseExtraParam licenseExtra) {
        userNum = Integer.parseInt(licenseExtra.getParams().get(paramType.getKey()).toString());
    }

    @Override
    public void uninstall() {
        userNum = 0;
    }

    @Override
    public ParamType paramType() {
        return UserNumVerifyListener.paramType;
    }

    public boolean verify(Integer userNum){
        return userNum < this.userNum;
    }
}
